package thread;

public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose=new Thread("rose"){
            public void run(){
                for (int i=0;i<5;i++){
                    System.out.println(getName()+":Let's me go!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
                System.out.println(getName()+":啊啊啊啊啊啊");
                System.out.println("扑通");
            }
        };
        Thread jack =new Thread("jack"){
          public void run(){
              while (true){
                  System.out.println(getName()+":you jump,i jump!");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
        };
        rose.start();
        jack.setDaemon(true);
        jack.start();
        while (true);//守护线程守护的是所有用户线程，只要有用户线程存在，守护线程就不会死
    }
}
